package com.example.leetdemo.finash;

import java.util.Stack;

public class Solution2390 {

    public String removeStars(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '*') {
                if (stack.size() > 0) {
                    stack.pop();
                }
            } else {
                stack.push(s.charAt(i));
            }
        }
        StringBuilder stringBuilder = new StringBuilder();
        while (stack.size() > 0) {
            stringBuilder.append(stack.pop());
        }

        return stringBuilder.reverse().toString();
    }
}
